<?php
/*
*团队基金接口类
*/
class teamFundAppClass extends appBase{
	/*团队基金-行政处罚*/
	public function penalty(){
		//赋值
		$staff = query("staff"," stid = '".$this->post['stid']."' ");
		//判断
		if(!$this->power("staff","penalty")){
			$json['warn'] = "您没有行政处罚的权限";
		}elseif(empty($this->post['stid'])){
			$json['warn'] = "请选择处罚员工";
		}elseif(empty($staff['stid'])){
			$json['warn'] = "未找到此员工";
		}elseif(empty($this->post['money'])){
			$json['warn'] = "请输入罚款金额";
		}elseif(preg_match(checkPrice,$this->post['money']) == 0){
			$json['warn'] = "罚款金额格式不正确";
		}elseif(empty($this->post['text'])){
			$json['warn'] = "请填写处罚原因";
		}elseif(empty($this->post['password'])){
			$json['warn'] = "请输入登录密码";
		}elseif(md5($this->post['password']) != $this->control['pas']){
			$json['warn'] = "登录密码输入错误";
		}else{
			//扣除员工账户相应余额
			$balance = $staff['money'] - $this->post['money'];
			update(array("table" => "staff","field" => array("money" => $balance,"updateTime" => date("Y-m-d H:i:s")),"where" => "stid = '".$staff['stid']."'"));
			record(array("type" => "员工会计账户","typeid" => $staff['stid'],"direction" => "支出","money" => $this->post['money'],"balance" => $balance,"text" => $this->post['text']));
			//累加团队基金
			$balance = para("teamFund") + $this->post['money'];
			paraEdit("teamFund",$balance);
			record(array("type" => "团队基金","typeid" => "teamFund","direction" => "收入","money" => $this->post['money'],"balance" => $balance,"text" => $staff['name']."被行政处罚，原因：".$this->post['text']));
			//添加日志
			$text = $this->control['name']."对".$staff['name']."作出了行政处罚，原因：".$this->post['text'];
			$this->logText(array("type" => "staff","text" => $text));
			//返回信息
			$json['warn'] = "success";
		}
		return $json;
	}
	/*列表页*/
	public function home(){
		if(!$this->power("teamFund","see")){
			$json['warn'] = "您没有查看团队基金的权限";
		}else{
			//like查询数组
			$like = array(
				"text" => $this->post['text'],//备注
			);
			//全等查询数组
			$equal = array(
				"direction" => $this->post['direction'],//方向
			);
			$and = "";
			//发生时间-开始日期
			if(!empty($this->post['startDay'])){
				$startDay = $this->post['startDay']." 00:00:00";
				$and .= " and time >= '$startDay' ";
			}
			//发生时间-结束日期
			if(!empty($this->post['endDay'])){
				$endDay = $this->post['endDay']." 23:59:59";
				$and .= " and time <= '$endDay' ";
			}
			//获取查询结果
			$where = "type = '团队基金' and typeid = 'teamFund'".search(array("like" => $like,"=" => $equal)).$and;
			$page = $this->page(array("table" => "record","where" => $where,"order" => "id desc"));
			//数据分析
			$json['teamFund'] = array();
			foreach($page['array'] as $array){
				$json['teamFund'][] = array(
					"id" => $array['id'],//主键
					"direction" => $array['direction'],//方向
					"money" => $array['money'],//金额
					"balance" => $array['balance'],//余额
					"text" => $array['text'],//备注
					"time" => $array['time'],//时间
				);
			}
			$json['money'] = para("teamFund");//团队基金账户余额
			//分页信息
			$json['page'] = $page['para'];
			//提示
			$json['warn'] = "success";
		}
		//返回
		return $json;
	}
	/*详情页*/
	public function detail(){
		$record = query("record","id = '".$this->post['id']."'");
		if(!$this->power("teamFund","see")){
			$json['warn'] = "您没有查看团队基金的权限";
		}elseif(empty($this->post['id'])){
			$json['warn'] = "团队基金记录ID为空";
		}elseif(empty($record['id'])){
			$json['warn'] = "未找到此记录";
		}else{
			$json['record'] = array(
				"direction" => $record['direction'],//方向
				"money" => $record['money'],//金额
				"balance" => $record['balance'],//余额
				"text" => $record['text'],//说明
				"time" => $record['time'],//时间
			);
			$json['warn'] = "success";
		}
		return $json;
	}
}
?>